package cn.luckdou.system.model.oss_file;

import org.apache.commons.lang.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;
import com.baomidou.mybatisplus.enums.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableName;
import java.io.Serializable;

/**
 * OSS文件
 * @author Dadou
 * @since 2018-06-05
 */
@TableName("tb_oss_file")
public class OssFile extends Model<OssFile> {

    private static final long serialVersionUID = 1L;

    /**
     * id
     */
	@TableId(value="id", type= IdType.AUTO)
	private Long id;
    /**
     * bucketName
     */
	private String bucket;
    /**
     * OssKey
     */
	@TableField("oss_key")
	private String ossKey;
    /**
     * fileName
     */
	private String name;
    /**
     * fileUrl
     */
	private String url;
    /**
     * 类型
     */
	private String type;
    /**
     * 状态 1正常 0停用
     */
	private Integer status;
    /**
     * 创建时间
     */
	@TableField("created_time")
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private Date createdTime;
    /**
     * 修改时间
     */
	@TableField("updated_time")
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private Date updatedTime;
    /**
     * 删除时间
     */
	@TableField("deleted_time")
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private Date deletedTime;
    /**
     * 编辑人
     */
	@TableField("created_editor")
	private String createdEditor;
    /**
     * 更新人
     */
	@TableField("updated_editor")
	private String updatedEditor;
	/**
	 * 无参构造方法
	 */
	public OssFile(){
	}

	public OssFile(String url, String name,String bucket,String hostAddress) {
		this.name=name;
		this.url=url;
		this.bucket=bucket;
		this.ossKey=url.replaceAll(hostAddress,"");
		this.createdTime=new Date();
		if (name.lastIndexOf(".")>=0){
			this.type=name.substring(name.lastIndexOf(".")+1);
		}

	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getBucket() {
		return bucket;
	}

	public void setBucket(String bucket) {
		this.bucket =StringUtils.isNotBlank(bucket)?bucket:null;
	}

	public String getOssKey() {
		return ossKey;
	}

	public void setOssKey(String ossKey) {
		this.ossKey =StringUtils.isNotBlank(ossKey)?ossKey:null;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name =StringUtils.isNotBlank(name)?name:null;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url =StringUtils.isNotBlank(url)?url:null;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type =StringUtils.isNotBlank(type)?type:null;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Date getCreatedTime() {
		return createdTime;
	}

	public void setCreatedTime(Date createdTime) {
		this.createdTime = createdTime;
	}

	public Date getUpdatedTime() {
		return updatedTime;
	}

	public void setUpdatedTime(Date updatedTime) {
		this.updatedTime = updatedTime;
	}

	public Date getDeletedTime() {
		return deletedTime;
	}

	public void setDeletedTime(Date deletedTime) {
		this.deletedTime = deletedTime;
	}

	public String getCreatedEditor() {
		return createdEditor;
	}

	public void setCreatedEditor(String createdEditor) {
		this.createdEditor =StringUtils.isNotBlank(createdEditor)?createdEditor:null;
	}

	public String getUpdatedEditor() {
		return updatedEditor;
	}

	public void setUpdatedEditor(String updatedEditor) {
		this.updatedEditor =StringUtils.isNotBlank(updatedEditor)?updatedEditor:null;
	}

	@Override
	protected Serializable pkVal() {
		return this.id;
	}

}
